package com.onerm.ui;

import java.util.Collections;
import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.google.common.collect.Lists;
import com.onerm.store.DataInterface;

public class ExercisesAdapter extends BaseAdapter {

  private final DataInterface db;
  private final List<String> exercises;

  public ExercisesAdapter(DataInterface db) {
    this.db = db;
    this.exercises = Lists.newArrayList(db.getExerciseNames());
    Collections.sort(exercises);
  }

  @Override
  public int getCount() {
    return exercises.size();
  }

  @Override
  public Object getItem(int position) {
    return exercises.get(position);
  }

  @Override
  public long getItemId(int position) {
    return exercises.hashCode();
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView != null) {
      TextView text = (TextView) convertView;
      text.setText(exercises.get(position));
      return text;
    }
    return PanelBuilder.newTextView(parent.getContext(), exercises.get(position));
  }

}
